<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$item=pdo_get('jy_weishop_coupon_sendticket',array('uniacid'=>$_SESSION['uniacid']));
	$item['limittime']=json_decode($item['limittime'],true);
	
	if($item['couponid']){
		$item['couponid']= explode(';', $item['couponid']);
		$cid=$item['couponid'];
		$item['couponid']= substr(implode(',', $item['couponid']),1,strlen(implode(',', $item['couponid']))-2);
		$where = 'and id in(' . $item['couponid'] . ')';
	}
	foreach($cid as $v){
		$c=pdo_get('jy_weishop_coupon',array('id'=>$v),array('backtype','getmax'));
		$t=pdo_count('jy_weishop_coupon_getlog',array('couponid'=>$v,'uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uniacid'],'gettype'=>1));
		if($c['getmax']>0 && $t<$c['getmax']){
			$data=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'couponid'=>$v,'gettype'=>1,'createtime'=>time(),'backtype'=>$c['backtype']);
			pdo_insert('jy_weishop_coupon_getlog',$data);
		}
		
	}
	$list = pdo_fetchall('select * from ' . tablename('jy_weishop_coupon') . ' where uniacid=:uniacid ' . $where, array(':uniacid' => $_SESSION['uniacid']), 'id');
	foreach($list as &$v){
		$v['limittimes']=json_decode($v['limittimes'],true);
		$v['limittimes']['tstart']=date('Y/m/d H:i:s',$v['limittimes']['tstart']);
		$v['limittimes']['tend']=date('Y/m/d H:i:s',$v['limittimes']['tend']);
		$v['time']=$v['limittimes']['tstart'].'至'.$v['limittimes']['tend'];
	}
	$return['list']=$list;
	exi($return);
}

?>